home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / SMALLTAL / SMALLT < prev    next >
Text File  |  1989-02-09  |  11KB  |  381 lines

  1. This file contains fixes to the following Smalltalk/V Mac bugs:
  2.         
  3. PRINTING
  4.  
  5. - ImageWriter printers don't print.
  6. - lines containing only a single CR don't print (this bug also causes
  7.   early termination of printing when the last line on a page is blank).
  8. - on a standard size page, the last line of output is clipped at
  9.   the bottom of the page.
  10. - when a line must be wrapped to fit the width of a page, the
  11.   last character of the line is lost.
  12. - the contents of a TextPane is always printed with the default font
  13.   rather than the font actually in the TextPane.
  14.  
  15. SCREEN
  16.  
  17. - with multiple monitors, Smalltalk/V Mac opens very large window
  18.   across all available screens;  grey area not restored on leaving
  19.   application.
  20.  
  21. ****** Note:  this file will file in OK on either Smalltalk/V Mac
  22.               or Smalltalk/V Mac 68000.
  23. "!
  24.  
  25. !MTrap class methods !
  26. PrPicFile: hPrint pPrPort: pPrPort pIOBuf: pIOBuf pDevBuf: pDevBuf prStatus: prStatus
  27.     "Printing Manager.
  28.         Print the spooled copy of the document.
  29.         WARNING: prStatus passed in as pointer but defined
  30.                  as record*.  Look at the sender of this method
  31.                  to see how this was done.
  32.         (Inside Macintosh II-160)"
  33.     <trap: stack long 16rA8FD handle pointer pointer pointer pointer 16r1480 16r6005>
  34.  
  35.     ^ self trapFailed! !
  36.  
  37. MType subclass: #TPrint
  38.   instanceVariableNames: ''
  39.   classVariableNames:
  40.     'THPrint PrintStatus'
  41.   poolDictionaries: ''!
  42.  
  43. !TPrint class methods !
  44. statusBuffer                               
  45.     "Answer a buffer to use for holding the printer status
  46.      information."    
  47.  
  48.     PrintStatus isNil ifTrue: [
  49.         PrintStatus := MPointer new: 26.
  50.     ].
  51.     ^ PrintStatus
  52. ! !
  53.  
  54. !TPrint class methods !
  55. invalidate
  56.     "Close and Nil out the THPrint."
  57.  
  58.     THPrint isNil ifFalse: [
  59.         MTrap PrClose.
  60.         THPrint := nil
  61.     ].
  62.     PrintStatus isNil ifFalse: [
  63.         PrintStatus dispose.
  64.         PrintStatus := nil.
  65.     ].
  66. ! !
  67.  
  68. !TPrint class methods !
  69. printSpooledDocument
  70.     "Cause the spooled document to be printed."
  71.  
  72.     self validate.
  73.     THPrint spooling ifTrue: [
  74.         MTrap PrPicFile: THPrint asParameter
  75.                 pPrPort: nil asParameter
  76.                  pIOBuf: nil asParameter
  77.                 pDevBuf: nil asParameter
  78.                prStatus: self statusBuffer asParameter
  79.     ]
  80. ! !
  81.  
  82. !MTrap class methods !
  83.  
  84. TextSize: n
  85.     "QuickDraw.
  86.         Set the text point size.
  87.         (Inside Macintosh I-171)"
  88.     <trap: stack procedure 16rA88A integer>
  89.  
  90.     ^ self trapFailed! !
  91.  
  92. !PrintStream methods !
  93. close
  94.     "Close the current page and the document."
  95.  
  96.     port closePage ifFalse: [
  97.         self error: 'error in printing'.
  98.     ].
  99.     port closeDocument ifFalse: [
  100.         self error: 'error in printing'.
  101.     ].
  102.     TPrint printSpooledDocument
  103. ! !
  104.  
  105. !PrintStream methods !
  106. printCurrentLine
  107.     "Print the current line on the printer."
  108.  
  109.     column ~= 1 ifTrue: [
  110.         line byteAtOffset: 0 put: column - 1.
  111.         Process enableInterrupts: false.
  112.         GrafPort pushTo: port.
  113.         self position: 1 @ row.
  114.         MTrap DrawString: line asParameter.
  115.         GrafPort pop.
  116.         Process enableInterrupts: true.
  117.     ].
  118.     row = pageHeight ifTrue: [ ^ self newPage ].
  119.     column := 1.
  120.     row := row + 1.
  121. ! !
  122.  
  123. !PrintStream methods !
  124. nextPut: aCharacter
  125.     "Write anObject to the receiver stream. Answer anObject."
  126.  
  127.     aCharacter = Cr
  128.         ifTrue: [ ^ self printCurrentLine ].
  129.     aCharacter = Ff
  130.         ifTrue: [ ^ self newPage ].
  131.     line byteAtOffset: column put: aCharacter asciiValue.
  132.     column := column + 1.
  133.     column = pageWidth
  134.         ifTrue: [ ^ self printCurrentLine ].
  135.     ^ aCharacter
  136. ! !
  137.  
  138. !PrintStream methods !
  139. initialize: aTPrPort
  140.     "Initialize the instance variables of the receiver
  141.      using the aTPrPort and the current TPrint record."
  142.     | size |
  143.  
  144.     port := aTPrPort.
  145.     port penNormal.
  146.     pageNumber := 1.
  147.     self font: (MacFont fontName: 'Monaco' pointSize: 12).
  148.     size := TPrint current pageSize.
  149.     pageWidth := (size x // (font width / 72) min: 255) - 1.
  150.     pageHeight := size y // (font height / 72) - 1.
  151.     row := 1.
  152.     column := 1.
  153.     line := Str255 newRecord.
  154.     port openPage.
  155. ! !
  156. !PrintStream class methods !
  157.  
  158. on: aTPrPort using: aFont
  159.     "Answer a new instance of the receiver which
  160.      which will print on aTPrPort."
  161.  
  162.     ^ self new initialize: aTPrPort using: aFont! !
  163.  
  164. !PrintStream methods !
  165.  
  166. initialize: aTPrPort using: aFont
  167.     "Initialize the instance variables of the receiver
  168.      using the aTPrPort and the current TPrint record."
  169.     | size |
  170.  
  171.     port := aTPrPort.
  172.     port penNormal.
  173.     pageNumber := 1.
  174.     self font: aFont.
  175.     size := TPrint current pageSize.
  176.     pageWidth := 255.
  177.     pageHeight := size y // (font height / 72).
  178.     row := 1.
  179.     column := 1.
  180.     line := Str255 newRecord.
  181.     port openPage.!
  182.  
  183. font: aFont
  184.     "Set the font to use for printing to aFont."
  185.  
  186.     aFont isMacFont ifFalse: [
  187.         self error: 'Font must be a MacFont'].
  188.  
  189.     font := aFont.
  190.     Process enableInterrupts: false.
  191.     GrafPort pushTo: port.
  192.     MTrap
  193.         TextFont: font glyphs;
  194.         TextSize: font pointSize.
  195.     GrafPort pop.
  196.     Process enableInterrupts: true.! !
  197.  
  198.  
  199. !TextPane methods !
  200.  
  201. print
  202.     "Print the contents of the receiver."
  203.     | port printStream |
  204.  
  205.     (port := TPrint print) isNil ifTrue: [ ^ self ].
  206.     printStream := PrintStream on: port using: curFont.
  207.     CursorManager execute change.
  208.     textHolder lines do: [ :line |
  209.         printStream nextPutAll: line; cr.
  210.     ].
  211.     printStream close.
  212.     CursorManager normal change! !
  213.  
  214.  
  215. "   *** This fix for multiple monitors works ONLY for Finder.  It's 
  216.     OK to file in even if you use MultiFinder, but doesn't fix the
  217.     problem."!
  218.  
  219. !MTrap class methods !
  220. InitWindows
  221.     "Window Manager.
  222.         Initialize the window system.
  223.         (Inside Macintosh I-281)"
  224.     <trap: stack procedure 16rA912>
  225.  
  226.     ^ self trapFailed! !
  227.  
  228. !SystemDictionary methods !
  229. startUp
  230.     "Initiate a Smalltalk/ V session by filing in the' go'
  231.      file. This message is sent by the virtual machine."
  232.      | sourceDirectory |
  233.  
  234.     "Set up the display screen."
  235.     MTrap InitWindows.
  236.     ScreenPort := Window windowManagerPort.
  237.     DisplayScreen Mac.
  238.  
  239.     "Force any menus in the image which may be added
  240.      to the menu bar to be properly initialized."
  241.     MenuBar message: 'Initializing╔'.
  242.     Menu startUp: false.
  243.  
  244.     "If go file specified, then file it in. If the
  245.      sources or changes files are unspecified afterwards,
  246.      file them in with the defaults."
  247.     Sources := Array new: 2.
  248.     sourceDirectory := Directory current.
  249.     Smalltalk openChangeLog: sourceDirectory.
  250.     Disk := (Sources at: 2) file directory.
  251.     (Disk hasFileNamed: 'go')
  252.         ifTrue: [ (Disk file: 'go') fileIn; close ].
  253.     (Sources at: 1) isNil
  254.         ifTrue: [ Sources at: 1 put: (sourceDirectory file: 'V.source') ].
  255.  
  256.     "Do any other required system initialization."
  257.     Time initialize.
  258.     CompiledMethod initializeUserPrimitives.
  259.     Smalltalk openFilesFromDeskTop.
  260.     MenuBar clear.
  261.     Process enableInterrupts: true.
  262.     Scheduler resume
  263. ! !
  264.  
  265. "   The following method causes windows to be opened on the main screen."!
  266.  
  267. !TopDispatcher class methods !
  268. nextFrame
  269.     "Answer a screen rectangle (global coordinates) in
  270.      which to stack the next window."
  271.     | aPoint mainWindowFrame |
  272.  
  273.     OpenPoint := OpenPoint isNil ifTrue:  [ 0 ]
  274.                                  ifFalse: [ OpenPoint + 1 ].
  275.     OpenPoint > 20
  276.         ifTrue: [ OpenPoint := 0 ].
  277.     aPoint :=
  278.         ((5 @ 18) * (OpenPoint \\ 5)) +
  279.             ((27 @ -2) * (OpenPoint // 5)) +
  280.                 (35 @ 50).
  281.  
  282.     mainWindowFrame := ScreenPort screenRect.
  283.     ^ aPoint + mainWindowFrame origin
  284.         corner:
  285.             aPoint + (mainWindowFrame corner * 3 // 4)
  286. ! !
  287.  
  288. "    The following method assures that menu bar messages
  289.      are displayed on the screen that has the menu bar."!
  290.  
  291. !MenuBar class methods !
  292. message: aString
  293.     "Display a message in the menu bar."
  294.     | rect |
  295.  
  296.     MTrap ClearMenuBar; DrawMenuBar.
  297.     aString displayAt: 10 @ 2 + Screen boundingBox origin negated
  298.                  font: Font menuFont
  299.                  dest: Screen
  300. ! !
  301.  
  302.  
  303. !GlobalDisplayScreen methods !
  304. boundingBox
  305.     "Answer a Rectangle which bounds the receiver."
  306.     | answer |
  307.  
  308.     answer := Region GrayRgn boundingBox.
  309.     answer origin y: (answer origin y min: 0). 
  310.     ^ answer
  311. ! !
  312.  
  313. "The following code causes error notifiers to pop up centered 
  314. on your main screen."!
  315.  
  316. !Debugger methods !
  317. walkbackFor: aProcess label: aString
  318.     "Pop-up a walkback window with label equal to aString).
  319.      Display the stacked message sends for the receiver in
  320.      the window."
  321.     | recursing extent logger listLineHeight aTopPane |
  322.  
  323.     process := aProcess.
  324.     recursing := RecursionInError.
  325.     maxLevel := 10.
  326.     RecursionInError
  327.         ifTrue: [
  328.             logger := Terminal.
  329.             logger cr; nextPutAll: 'error: ',aString; cr]
  330.         ifFalse: [
  331.             RecursionInError := true.
  332.             logger := WriteStream on: (String new: 40).
  333.         ].
  334.     aProcess walkbackOn: logger maxLevels: maxLevel.
  335.     RecursionInError := false.
  336.     Process enableInterrupts: true.
  337.     recursing ifTrue: [
  338.         ^ Smalltalk exit: false
  339.     ] ifFalse: [
  340.         extent := ((350 max:
  341.                     (LabelFont stringWidth: aString) + 40) min:
  342.                         ScreenPort screenRect width - 20)
  343.                     @ 250.
  344.         label := aString.
  345.         listLineHeight := Font menuFont height + 8.
  346.         aTopPane := TopPane new.
  347.         aTopPane
  348.             label: label;
  349.             model: self;
  350.             menu: #walkbackMenu;
  351.             minimumSize: 200@100;
  352.             addSubpane:
  353.                 (TextPane new
  354.                     model: logger contents;
  355.                     framingBlock: [ :box |
  356.                         box origin + (0 @ listLineHeight)
  357.                             corner: box corner
  358.                     ]).
  359.         aTopPane addSubpane:
  360.             (ButtonPane new
  361.                 model: self;
  362.                 buttons: #(Resume Debug);
  363.                 framingBlock: [ :box |
  364.                     box origin corner: box width @ listLineHeight
  365.                 ];
  366.                 pulse: true).
  367.         aTopPane dispatcher
  368.             openIn: (ScreenPort screenRect extent // 2
  369.                         - (extent // 2)
  370.                             extent: extent);
  371.             scheduleWindow.
  372.         Scheduler run
  373.     ]
  374. ! !
  375.  
  376.  
  377.  
  378.  
  379.